﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;

namespace GIAODIEN
{
    public partial class frmdocgia : Form
    {
        public frmdocgia()
        {
            InitializeComponent();
        }
        BUS_DocGia obj = new BUS_DocGia();
        DataTable dtDocGia=new DataTable();
        int maDG;
        private void frmdocgia_Load(object sender, EventArgs e)
        {
            lblNgayHienHanh.Text += System.DateTime.Today.ToShortDateString();
            lblNhanVien.Text += bientoancuc.ttnhanvien.TenNhanVien;
            bientoancuc.docgia = 1;
            dtDocGia= obj.LayDSDocGia();
            dtgdocgia.DataSource = dtDocGia;
            maDG = obj.LayGiaTriMaDGLonNhat();
        }

        private void btnthemdg_Click(object sender, EventArgs e)
        {
            if (obj.CapNhatDuLieu_BUS(dtDocGia) == true)
            {
                MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK);
            }
            else {
                MessageBox.Show("Thêm không thành công", "Thông báo", MessageBoxButtons.OK);
            }
        }

        private void frmdocgia_FormClosing(object sender, FormClosingEventArgs e)
        {
            bientoancuc.docgia = 0;
        }
        
        private void dtgdocgia_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (e.RowIndex == (dtDocGia.Rows.Count) && dtgdocgia.Rows[e.RowIndex].Cells[0].Value.ToString()=="")
            {
                dtgdocgia[0, e.RowIndex].Value = maDG+1;
                dtgdocgia[6, e.RowIndex].Value = bientoancuc.ttnhanvien.MaNhanVien;
                dtgdocgia[5, e.RowIndex].Value = System.DateTime.Today.ToShortDateString();
                maDG+=1;
            }
        }

        private void btnxoadg_Click(object sender, EventArgs e)
        {
            foreach(DataGridViewRow dgr in dtgdocgia.Rows){
                if (dgr.Selected == true) {
                    dtgdocgia.Rows.Remove(dgr);
                }
            }
        }

        private void btnthoatdg_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
